package version2024.easy;

import java.util.Scanner;

/**
 * @author sunhl
 * @Description:
 * @Date: created in 2025/1/14 星期二 16:31
 * @Modified By:
 */
public class HJ31_WordInvertedIndex {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            String res = reverse(str);
            System.out.println(res);
        }
    }

    public static String reverse(String str) {
        // 匹配非字母的字符进行分割
        String[] words = str.split("[^A-Za-z]");
        StringBuilder result = new StringBuilder();

        // 逆序添加分割完的单词
        for (int i = words.length - 1; i >= 0; i--) {
            result.append(words[i]).append(" ");
        }
        return result.toString().trim();
    }
}
